/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package holdem.pokergui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author Anders
 */
public class Player extends JLabel
{
    public static final int WIDTH = 100;
    public static final int HEIGHT = 100;
    private MyCard[] hand = new MyCard[2];
    private boolean isActive = false;
    private String name;
    private int money;
    private boolean me;

    public Player()
    {
        setPreferredSize(new Dimension(WIDTH+18, HEIGHT+30));
    }

    public boolean isActive()
    {
        return isActive;
    }

    public void setMe(boolean me)
    {
        this.me = me;
        repaint();
    }

    public void joinGame(String name, int money)
    {
        isActive = true;
        this.name = name;
        this.money = money;
        repaint();
    }
    
    public void leavGame()
    {
        isActive = false;
    }

    public MyCard[] getHand()
    {
        return hand;
    }

    public void setHand(MyCard[] hand)
    {
        this.hand = hand;
        repaint();
    }

    @Override
    public String getName()
    {
        return name;
    }

    public int getMoney()
    {
        return money;
    }

    public void setMoney(int money)
    {
        this.money = money;
        repaint();
    }

    @Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        if(me)
        {
            if(hand[0] != null)
            {
                g.drawImage(hand[0].img().getImage(), 0, 0, WIDTH, HEIGHT, this);
                g.drawImage(hand[1].img().getImage(), 18, 0, WIDTH, HEIGHT, this);
                g.drawString(name + " " + money + "$", 30, 120);
            }
            else
            {
                Image tmp = new ImageIcon("poker.jpg").getImage();
                g.drawImage(tmp, 0, 0, WIDTH, HEIGHT, this);
            }
        }
        else if(isActive)
        {
           if(hand[0] != null)
            {
                g.drawImage(hand[0].img().getImage(), 0, 0, WIDTH, HEIGHT, this);
                g.drawImage(hand[1].img().getImage(), 18, 0, WIDTH, HEIGHT, this);
                g.drawString(name + " " + money + "$", 30, 120);
            }
           else
           {
                Image tmp = new ImageIcon("hello.png").getImage();

                g.drawImage(tmp, 0, 0, WIDTH, HEIGHT, this);
                g.drawImage(tmp, 18, 0, WIDTH, HEIGHT, this);
                g.drawString(name + " " + money + "$", 30, 120);
           }
        }
        else
        {
           Image tmp = new ImageIcon("empty.jpg").getImage();
           g.drawImage(tmp, 0, 0, WIDTH, HEIGHT, this);
           g.drawString("Empty chair", 20, 120);
        }
    }
}